<template>
  <div class="job-seeker-home">
    <header class="header">
      <h1>我要当牛马</h1>
    </header>
    <main class="main-content">
      <section class="search-section">
        <h2>搜索职位</h2>
        <input type="text" v-model="searchQuery" placeholder="输入关键词搜索职位" class="search-input" />
        <button @click="searchJobs" class="search-button">搜索</button>
      </section>
      <section class="job-listings">
        <h2>推荐职位</h2>
        <div v-if="jobs.length === 0" class="no-jobs">
          暂无推荐职位
        </div>
        <div v-else class="job-item" v-for="job in jobs" :key="job.id">
          <h3>{{ job.title }}</h3>
          <p>{{ job.company }}</p>
          <p>{{ job.salary }}</p>
          <p>{{ job.location }}</p>
          <p>{{ job.description }}</p>
          <p>{{ job.requirements }}</p>
          <button @click="applyForJob(job.id)" class="apply-button">申请</button>
        </div>
      </section>
    </main>
  </div>
</template>

<script setup>
import {ref, computed, onMounted} from 'vue';
import axios from "axios";
onMounted(() => {
  findAllJobs();
});
// 示例数据
const jobs = ref([]);
const findAllJobs =()=>{
  axios.get(BASEURL+'/jobSeeker/getAllJobs').then((response)=> {
    console.log('职位列表:', response.data);
      if (response.data.code===2000) {
        jobs.value = response.data.data;
      }
  });
}
const searchQuery = ref('');

const filteredJobs = computed(() => {
  return jobs.value.filter(job =>
      job.title.toLowerCase().includes(searchQuery.value.toLowerCase()) ||
      job.company.toLowerCase().includes(searchQuery.value.toLowerCase()) ||
      job.location.toLowerCase().includes(searchQuery.value.toLowerCase())
  );
});

const searchJobs = () => {
  console.log('搜索职位:', searchQuery.value);
};

const applyForJob = (jobId) => {
  console.log('申请职位:', jobId);
};
</script>

<style scoped>
.job-seeker-home {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.header {
  background-color: #4CAF50;
  color: white;
  padding: 10px 0;
  text-align: center;
}

.main-content {
  flex: 1;
  padding: 20px;
}

.search-section {
  margin-bottom: 20px;
}

.search-input {
  padding: 10px;
  width: 80%;
  margin-right: 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.search-button {
  padding: 10px 20px;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.search-button:hover {
  background-color: #45a049;
}

.job-listings {
  margin-top: 20px;
}

.job-item {
  background-color: #f9f9f9;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 15px;
  margin-bottom: 15px;
}

.job-item h3 {
  margin: 0 0 10px;
}

.job-item p {
  margin: 5px 0;
}

.apply-button {
  padding: 10px 20px;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.apply-button:hover {
  background-color: #45a049;
}

.no-jobs {
  text-align: center;
  padding: 20px;
  color: #666;
}


</style>
